
#ifndef DeviceFamily_CC26X4
#define DeviceFamily_CC26X4
#endif

#include <ti/devices/DeviceFamily.h>

#include "ti_drivers_config.h"
/*
 *  =============================== GPIO ===============================
 */

#include <ti/drivers/GPIO.h>
#include <ti/drivers/gpio/GPIOCC26XX.h>

/*
 *  =============================== RF Driver ===============================
 */
#include <ti/drivers/GPIO.h>
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/ioc.h)
#include <ti/drivers/rf/RF.h>

/*
 * ======== Antenna switching ========
 */
/*
 * ======== rfDriverCallbackAntennaSwitching ========
 * Sets up the antenna switch according to the TX power table PA type.
 *
 * Truth table:
 *
 * Path       DIO28 DIO29
 * ========== ===== ===== 
 * Off        0     0
 * 2.4 GHZ    1     0
 * HIGH PA    0     1
 */
void rfDriverCallbackAntennaSwitching(RF_Handle client, RF_GlobalEvent events, void *arg)
{

    if (events & RF_GlobalEventRadioSetup) {
        /* Switch off all paths. */
        GPIO_write(CONFIG_RF_HIGH_PA, 0);
        GPIO_write(CONFIG_RF_24GHZ, 0);

        /* Decode the current PA configuration. */
        RF_TxPowerTable_PAType paType = (RF_TxPowerTable_PAType)RF_getTxPower(client).paType;

        if (paType == RF_TxPowerTable_HighPA) {
            /*
            * Mux GPIOs to RF Core signals:
            * - High PA    --> HIGH PA
            * - LNA enable --> 2.4 GHz  
            */
            GPIO_setConfigAndMux(CONFIG_RF_HIGH_PA, GPIO_CFG_OUTPUT,IOC_PORT_RFC_GPO3);
            GPIO_setConfigAndMux(CONFIG_RF_24GHZ, GPIO_CFG_OUTPUT, IOC_PORT_RFC_GPO0);
        } else {
            /* RF Core active --> 2.4 GHz   */
            GPIO_write(CONFIG_RF_24GHZ, 1);
        }
    }
    else if (events & RF_GlobalEventRadioPowerDown) {
        /* Switch off all paths. */
        GPIO_write(CONFIG_RF_24GHZ, 0);
        GPIO_write(CONFIG_RF_HIGH_PA, 0);

        /* Reset the IO multiplexer to GPIO functionality */
        GPIO_setConfigAndMux(CONFIG_RF_24GHZ, GPIO_CFG_OUTPUT, IOC_PORT_GPIO);
        GPIO_setConfigAndMux(CONFIG_RF_HIGH_PA, GPIO_CFG_OUTPUT, IOC_PORT_GPIO);
    }
}
